package com.chat.result;

import lombok.Data;

import java.io.Serializable;

/**
 * 后端统一返回结果
 *
 * @param <T>
 */
@Data
public class Result<T> implements Serializable {
    private static final int SUCCESS_CODE = 200;
    private static final int ERROR_CODE = 500;
    private static final int TOKEN_ERROR_CODE = 401;
    private static final int TOKEN_REFRESH_CODE = 433;

    private Integer code;
    private String msg; //错误信息
    private T data; //数据

    public static <T> Result<T> success(String msg, T data) {
        Result<T> result = new Result<T>();
        result.code = SUCCESS_CODE;
        result.msg = msg;
        result.data = data;
        return result;
    }

    public static <T> Result<T> error(String msg) {
        Result result = new Result();
        result.msg = msg;
        result.code = ERROR_CODE;
        return result;
    }
}
